<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>作用域插槽</title>
</head>
<style type="text/css">
    .current {
        color: orange;
    }
</style>
<body>
<div id="app">
    <fruit-list :list="list">
        <template slot-scope="slotProps">
            <strong v-if="slotProps.info.id==2" class="current">{{slotProps.info.name}}</strong>
            <strong v-else>{{slotProps.info.name}}</strong>
        </template>
    </fruit-list>
</div>

<!-- 开发环境版本，包含了有帮助的命令行警告 -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script type="text/javascript">
    /*
    作用域插槽-父组件对子组件的内容进行加工处理
     */
    Vue.component("fruit-list", {
        props: ["list"],
        template: `
            <div>
                <li :key="item.id" v-for="item in list">
                    <slot :info="item">{{item.name}}</slot>
                </li>
            </div>
        `
    })

    var vue = new Vue({
        el: "#app",
        data: {
            list: [{
                id: 1,
                name: "apple"
            }, {
                id: 2,
                name: "orange"
            }, {
                id: 3,
                name: "banana"
            }]
        }
    })
</script>
</body>
</html>
